<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="操作时间">
          <el-date-picker
            v-model="daterangeCreateTime"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="业务名称" prop="executionName">
          <el-input
            v-model="queryParams.executionName"
            placeholder="请输入业务名称(操作了哪个方法)"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="操作人" prop="executionPeople">
          <el-input
            v-model="queryParams.executionPeople"
            placeholder="请输入操作人"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="ip地址" prop="executionIp">
          <el-input
            v-model="queryParams.executionIp"
            placeholder="请输入操作的ip地址"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="日志分类" prop="logType">
            <el-select v-model="queryParams.logType">
                <el-option :value="0" label="竞赛" />
                <el-option :value="1" label="文章" />
                <el-option :value="2" label="提问" />
                <el-option :value="3" label="活动" />
            </el-select>
        </el-form-item>
        <el-form-item label="操作分类" prop="executionType">
            <el-select v-model="queryParams.executionType">
                <el-option :value="0" label="增加" />
                <el-option :value="1" label="删除" />
                <el-option :value="2" label="修改" />
            </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:log:export']"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="日志编号" align="center" prop="id" />
        <el-table-column label="执行方法" align="center" prop="executionName" />
        <el-table-column label="操作人" align="center" prop="executionPeople" />
        <el-table-column label="操作类型" align="center" prop="executionType" />
        <el-table-column label="操作时间" align="center" prop="createTime" />
        <el-table-column label="操作地址" align="center" prop="executionIp" />
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </template>
  
  <script>
  import { listLog } from "@/api/log/log";
  
  export default {
    name: "Log",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 日志信息表格数据
        logList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 哪一个的日志信息 0:竞赛 1:文章 2:提问 3:活动时间范围
        daterangeCreateTime: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          createTime: null,
          executionName: null,
          executionPeople: null,
          executionType: null,
          executionIp: null,
          logType: 0
        },
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询日志信息列表 */
      getList() {
        this.loading = true;
        this.queryParams.params = {};
        if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
          this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
          this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
        }
        listLog(this.queryParams).then(response => {
          this.logList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
        console.log(this.queryParams)
      },
      // 表单重置
      reset() {
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeCreateTime = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('log/export', {
          ...this.queryParams
        }, `log_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
   